// 该文件用于创建整个应用的路由器
import VueRouter from "vue-router"

import About from "../pages/About.vue"
import Home from "../pages/Home.vue"
import News from "../pages/News.vue"
import Message from "../pages/Message.vue"
import Detail from "../pages/Detail.vue"

// 创建一个路由器
const router = new VueRouter({
    routes: [
        {
            // name跳转时减少编码
            name: "guanyu",
            path: "/about",
            component: About
        },
        {
            path: "/home",
            component: Home,
            children: [
                {
                    path: "news",
                    component: News
                },
                {
                    path: "message",
                    component: Message,
                    children: [
                        {
                            name: "xiangqing",
                            path: "detail/:id/:title",
                            component: Detail,
                            // props写法一，该对象中所有key-value都会以props形式传
                            // props: { a: 1, b: "hello" }

                            // props写法二一，值为布尔值，若布尔值为真，将收到的所有params参数以props参数传
                            //  props: true

                            // props写法三，值为函数
                            props($route) {
                                return { id: $route.query.id, title: $route.query.title }
                            }

                            // props({ query: { id, title } }) {
                            //     return { id, title }
                            // }
                        }
                    ]
                }
            ]
        }
    ]
})
export default router